<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2022-11-08 14:05:13
 * @Last Modified time: 2023-02-18 17:34:38
 */
namespace app\common\enum;
use think\Container;
/**
 * 基类
 * Class EnumInstance
 */
abstract class EnumInstance
{

    protected static $data;

    public static $class = [
        'status'=> '\\app\\common\\enum\\StatusEnum',
        'system'=> [
            'menus'=>[],
            'config'=>[
                'type'=>'\\app\\common\\enum\\system\\config\\TypeEnum',
                'input_type'=>'\\app\\common\\enum\\system\\config\\InputTypeEnum'
            ],
            'addon'=>[
                'type'=>'\\app\\common\\enum\\system\\addon\\TypeEnum',
            ]
        ],
        'store'=>[
            'delivery_type'=>'\\app\\common\\enum\\store\\DeliveryTypeEnum',
            'delivery_shipping'=>'\\app\\common\\enum\\store\\DeliveryShippingEnum',
            'shipping'=>[
                'type'=>'\\app\\common\\enum\\store\\shipping\\TypeEnum',
            ],
            'goods'=>[
                'spec_type'=>'\\app\\common\\enum\\store\\goods\\SpecTypeEnum',
                'status'=>'\\app\\common\\enum\\store\\goods\\StatusEnum',
                'comment'=>'\\app\\common\\enum\\store\\goods\\CommentEnum',
            ],
            'order'=>[
                'source'=>'\\app\\common\\enum\\store\\order\\SourceEnum',
                'status'=>'\\app\\common\\enum\\store\\order\\StatusEnum',
                'delivery_status'=>'\\app\\common\\enum\\store\\order\\DeliveryStatusEnum',
                'receipt_status'=>'\\app\\common\\enum\\store\\order\\ReceiptStatusEnum',
                'refund_type'=>'\\app\\common\\enum\\store\\order\\RefundTypeEnum',
                'refund_status'=>'\\app\\common\\enum\\store\\order\\RefundStatusEnum',
            ],
        ],
        'user'=>[
            'register_source'=>'\\app\\common\\enum\\user\\RegisterSourceEnum',
            'status'=>'\\app\\common\\enum\\user\\StatusEnum',
            'water_source'=>'\\app\\common\\enum\\user\\WaterSourceEnum'
        ],
        'pay'=>[
            'type'=>'\\app\\common\\enum\\pay\\PayTypeEnum',
            'status'=>'\\app\\common\\enum\\pay\\PayStatusEnum'
        ]
    ];
    public function __construct(){
    }

    /**
     * 静态实例对象
     * @param array $args
     * @return static
     */
    public static function instance(...$args)
    {
        $class = static::$class;
        if(!empty($args[0])){
            $source = explode('.',$args[0]);
            foreach ($source as $item) {
                $class = $class[$item];
            }
            static::$data = $class::data();
        }
        return Container::getInstance()->make(static::class, $args);
    }

    public static function getAll(){
    	$classAll = static::getClass(static::$class);
    	$data = [];
        foreach ($classAll as $key => $value) {
        	$itemKey = str_replace("\\app\\common\\enum\\","",$value);
        	$itemKey = str_replace("\\",".",$itemKey);
        	$data[$itemKey] =  $value::data();
        }
        return $data;
    }

    public static function getClass($data){
    	$classData = [];
    	foreach ($data as $key => $value) {
        	if(is_array($value)){
        		$classData = array_merge(static::getClass($value),$classData);
        	}else{
        		$classData[] = $value;
        	}
    	}
    	return $classData;
    }
}

